﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Text;
using System.Data;
using System.Collections;
using Intergr8.Data;

namespace Visualization.ResponseGenerator
{
    /// <summary>
    /// Generate a response string
    /// </summary>
    public class ResponseBuilder
    {
        private string _version = "0.6";
        private string _reqId = "0";
        private string _status = "OK";
        private string _sig = "1068688546";

        private string _table = "";
        private string _header = "";


        

        public ResponseBuilder(DataTable table)
        {
         
            Bortosky.Google.Visualization.GoogleDataTable gdt = new Bortosky.Google.Visualization.GoogleDataTable(table);

            using (System.IO.MemoryStream mem = new System.IO.MemoryStream())
            {
                gdt.WriteJson(mem);
                mem.Position = 0;
                System.IO.StreamReader sr = new System.IO.StreamReader(mem);
                _header = String.Format("version:'{0}',reqId:'{1}',status:'{2}',sig:'{3}'", _version,_reqId,_status,_sig);
                _table = "table:" + sr.ReadToEnd();

                sr.Close();
            }
        }

        public string Response
        {
            get {

                string response = "google.visualization.Query.setResponse({" + _header + "," + _table + "})";
                return response;
            }
        }


    }
}
